<template>
    <div class="conMain">
        <!-- <div class="nav-btn-box">
            <button
                :class="['btn-item' ,currNavTab == item.key ? `btn-${item.key}-active` : '']"
                v-for="(item, index) in tabList" :key="index"
                @click="switchNavTab(item.key)">
                {{item.title}}
            </button>
        </div> -->
        <div v-if="currNavTab != 'mtain' && currNavTab != 'cloth'" class="not-print">
            <div class="lis-tabs ">
                <div :class="['tabs-item',{'is-active':currTab=='day'}]" @click="showList('day')">单日查询</div>
                <div :class="['tabs-item',{'is-active':currTab=='month'}]" @click="showList('month')">月份流水</div>
            </div>
            <!--搜索-->
            <div class="fill-wrap " v-if="isShowList == 'day'">
                <date-fill
                    :date="orderTime"
                    :option="orderOption"
                ></date-fill>
                <a href="javascript:void(0)" class="btn search-btn" @click="loadLis">检索</a>
                <a href="javascript:void(0)" class="btn print-btn" v-show="allPrint>0" @click="printAll">打印全部（{{allPrint}}）</a>
                <a href="javascript:void(0)" class="btn print-btn" v-show="isToday && noPrintList.length > 0" title="打印今日还没有打印的" @click="printRest">打印今日剩余（{{noPrintList.length}}）</a>
                <a href="javascript:void(0)" class="btn print-btn"  v-show="allPrint>0" title="打印选择的"  @click="printSelect">打印选中（{{selectPrint}}）</a>
                <a href="javascript:void(0)" class="btn print-btn" v-show="selectPrint>0 && (allPrint-selectPrint) > 0"  title="打印没有选择的"  @click="printNoSelect">反选及打印（{{allPrint-selectPrint}}）</a>
                <a href="javascript:void(0)" class="btn print-btn" v-show="selectPrint>0"  @click="printCancelSelect">取消选择</a>
                <el-checkbox  v-show="allPrint>0" v-model="badSortChecked" @change="handleChangeCheck">按床号升序打印</el-checkbox>

                <div class="filtrate-about">
                    <el-button
                        v-for="item in filtrateLis"
                        :key="item.key"
                        :type="filtrateKey==item.key ? 'primary':'info'"
                        :plain="filtrateKey==item.key ? false:true"
                        :title="item.title"
                        @click="handleSetKeyShowLis(item.key)"
                        size="mini">{{item.name}}</el-button>
                </div>
            </div>
            <div class="fill-wrap  month-tab" v-if="isShowList == 'month'">
                <date-picker v-model="monthVal" type="month" format="YYYY-MM" :clearable="false" placeholder="请选择具体年月" @change="loadLis()"></date-picker>
                <input type="text" placeholder="请输入输送类型" v-model="typeVal" class="type-input" @keyup.enter="loadLis">
                <a href="javascript:void(0)" class="btn search-btn" @click="loadLis">检索</a>
            </div>
            <div class="no-txt"
                 v-if="!isLoad && ((currTab == 'day' && doing.length == 0 && done.length == 0) || (currTab == 'month' && monthLis.length == 0))"
            >暂无数据</div>
        </div>

        <div v-if="isLoad" class="no-txt"><load></load> 正在加载，请稍后</div>


        <!-- 维修单列表 -->
        <div v-if="!isLoad && currNavTab == 'mtain'">
            <div class="no-txt"
                 v-if="mtDoing.length == 0 && mtDone.length == 0 "
            >暂无数据</div>
            <div class="order-lis" v-else>
                <div class="mtain-overview">
                    <i></i>
                    <span v-for="(item, index) in mtView" :key="index">{{item.title}}：{{item.num}}</span>
                </div>
                <div class="table-wrap">
                    <table>
                        <thead class="mtain-thead">
                        <tr>
                            <td>序号</td>
                            <td>创建时间</td>
                            <td>进度</td>
                            <td>申报科室</td>
                            <td>详细地址</td>
                            <td>申报人信息</td>
                            <td>申报项目</td>
                            <td>处理人</td>
                            <td>处理人电话</td>
                            <td>评价</td>
                        </tr>
                        </thead>
                        <tbody class="mtain-tbody">
                        <tr v-for="item in mtDoing"
                            :key="item.id"
                            class="mtain-doing-tr"
                            @click.stop="showMtDetails(item.id, 0)">
                            <td class="mtain-doing-border">{{item.id}}</td>
                            <td>{{item.createdtime}}</td>
                            <td :class="item.is_suspend == 1 && item.tsid != 3?'suspend':''">
                                <span v-if="item.is_suspend == 1 && item.tsid != 3">挂单</span>
                                <span v-else>{{item.statu=='已完成' && item.attribute==5 ? '服务已转交':item.statu}}</span>
                            </td>
                            <td>{{item.department}}</td>
                            <td>{{item.address}}</td>
                            <td>{{item.applicant}}</td>
                            <td>{{item.bigclass}}-{{item.smallclass}}</td>
                            <td>{{item.dealwiths.map(v => v.name).join('，')}}</td>
                            <td :title="item.dealwiths.map(v => v.phone).join('，')">
                                <span v-if="item.dealwiths.length != 0">{{item.dealwiths[0].phone}}</span>
                                <span v-if="item.dealwiths.length > 1">...</span>
                            </td>
                            <td class="icon-comment-td" @click.stop="showMtCommentPop(item)"><img :src="item.evaIcon" alt=""></td>
                        </tr>
                        <tr v-for="item in mtDone"
                            :key="item.id"
                            class="mtain-done-tr"
                            @click.stop="showMtDetails(item.id, 1)">
                            <td class="mtain-done-border">{{item.id}}</td>
                            <td>{{item.createdtime}}</td>
                            <td :class="item.is_suspend == 1 && item.tsid != 3?'suspend':''">
                                <span v-if="item.is_suspend == 1 && item.tsid != 3">挂单</span>
                                <span v-else>{{item.statu=='已完成' && item.attribute==5 ? '服务已转交':item.statu}}</span>
                            </td>
                            <td>{{item.department}}</td>
                            <td>{{item.address}}</td>
                            <td>{{item.applicant}}</td>
                            <td>{{item.bigclass}}-{{item.smallclass}}</td>
                            <td>{{item.dealwiths.map(v => v.name).join('，')}}</td>
                            <td>
                                <span v-if="item.dealwiths.length != 0">{{item.dealwiths[0].phone}}</span>
                                <span v-if="item.dealwiths.length > 1">...</span>
                            </td>
                            <td class="icon-comment-td" @click.stop="showMtCommentPop(item)"><img :src="item.evaIcon" alt=""></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>


        <!-- 输送单列表-->
        <!-- 月份流水 -->
        <div class="order-lis" v-if="currNavTab == 'trans' && monthLis.length > 0 && isShowList == 'month'">
            <div class="table-wrap">
                <table>
                    <thead class="mon-thead">
                    <tr>
                        <td>订单编号</td>
                        <td>订单类型</td>
                        <td>订单状态</td>
                        <td>时间</td>
                        <td>输送类型</td>
                        <td>携带设备</td>
                        <td>输送起点</td>
                        <td>床号</td>
                        <td>输送员</td>
                        <td>已打印</td>
                        <td>评价</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item,index) in monthLis" :key="index"
                        :class="['mon',$root.$data.sOrderAttr[item.attribute]?$root.$data.sOrderAttr[item.attribute].lisClass:'',
                        item.len == undefined?'ing':'white',
                        {
                            'orange':item.statu == 4 ,
                            'selected':item.selected
                        }]"
                        @click.stop="lookDetail(item.id,index,1)"
                    >
                        <template v-if="item.len != undefined">
                            <td><span>{{item.currYear}}</span></td>
                            <td><span>-{{item.currMonth}}-</span></td>
                            <td><span>{{item.currDate}}</span></td>
                            <td><span>({{item.len}})</span></td>
                            <td v-for="(val,idx) in 6" :key="idx"></td><!-- 补右侧剩余空位 -->
                        </template>

                        <template v-if="item.len == undefined">
                            <td style="background: none;">{{item.sn}}</td>
                            <td>
                                <span>{{$root.$data.sOrderAttr[item.attribute]?$root.$data.sOrderAttr[item.attribute].name:''}}</span>
                            </td>
                            <td>
                                <span >{{$root.$data.sStatus[item.statu]}}</span>
                            </td>
                            <td>
                                <span v-if="item.istoday" class="istoday"></span>
                                <span v-if="!item.isHis">
                                {{item.createdtime.substr(item.createdtime.length-8,item.createdtime.length-3)}} 创建
                                </span>
                                <span v-else>
                                {{item.hiscreatedtime.substr(item.hiscreatedtime.length-8,item.hiscreatedtime.length-3)}} 发布
                                </span>
                                <div v-if="item.attribute ==2 || item.attribute == 8">
                                    预约时间 {{item.appointment.substring(5)}}
                                </div>
                            </td>
                            <td>{{item.classifyname}}/{{item.catalogname}}</td>
                            <td>{{item.tackle == '' ? '无' : item.tackle}}</td>
                            <td>{{item.startaddress}}</td>
                            <td>{{item.startbed}}</td>
                            <td>
                                <div>
                                    <span class="inline-block" v-for="(staff,index) in item.receive" :key="index">{{staff.receive}}<a href="javascript:void(0)" class="hint tel"><span class="hint-txt">{{staff.tel}}</span></a>　</span>
                                </div>
                            </td>
                            <td>
                                <el-tooltip  placement="top" effect="light" popper-class="printTime">
                                    <div class="printTime" slot="content">
                                            打印时间：
                                            <ul>
                                                <li v-for="printitem in item.print_flows">
                                                    {{printitem.ctime}}
                                                </li>
                                            </ul>
                                        </div>
                                    <div class="print-status" v-if="item.print_flows.length>0">
                                        <span></span>

                                    </div>
                                </el-tooltip>
                            </td>
                            <td class="icon-comment-td" @click.stop="showCommentPop(item)"><img :src="item.evaIcon" alt=""></td>
                        </template>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 单日查询 -->
        <div :class="['order-lis',{'mores':allPrint>13} ]" v-if="currNavTab == 'trans' && !isLoad && (doing.length > 0 || done.length > 0) && isShowList == 'day'">
            <!--待指派，待接单（急单，预约单，普通单）-->
            <div :class="['table-wrap',{'opacity':selectPrint > 0}]" >
                <table>
                    <thead>
                    <tr>
                        <td>选择</td>
                        <td>订单编号</td>
                        <td>订单类型</td>
                        <td>订单状态</td>
                        <td>时间</td>
                        <td>输送类型</td>
                        <td>携带设备</td>
                        <td>输送起点</td>
                        <td>床号</td>
                        <td>输送员</td>
                        <td>已打印</td>
                        <td>评价</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item,index) in doing"
                        :key="index"
                        :class="[
                            'ing','day',$root.$data.sOrderAttr[item.attribute]?$root.$data.sOrderAttr[item.attribute].lisClass:'',
                            {'orange':item.statu == 4 ,'selected':item.selected}
                        ]"
                        @click.stop="lookDetail(item.id,index,1)">
                        <td @click.stop="handleSelectPrint(0,index)"><a  :class="['select-btn',{'select':item.selected}]"></a></td>
                        <td>{{item.sn}}</td>
                        <td>
                            <span>{{$root.$data.sOrderAttr[item.attribute]?$root.$data.sOrderAttr[item.attribute].name:''}}</span>
                        </td>
                        <td>
                            <span >{{$root.$data.sStatus[item.statu]}}</span>
                        </td>
                        <td>
                            <span v-if="item.istoday" class="istoday"></span>
                            <span v-if="!item.isHis">
                            {{item.createdtime.substr(item.createdtime.length-8,item.createdtime.length-3)}} 创建
                            </span>
                            <span v-else>
                            {{item.hiscreatedtime.substr(item.hiscreatedtime.length-8,item.hiscreatedtime.length-3)}} 发布
                            </span>
                            <div v-if="item.attribute ==2 || item.attribute == 8">
                                预约时间 {{item.appointment.substring(5)}}
                            </div>
                        </td>
                        <td>{{item.classifyname}}/{{item.catalogname}}</td>
                        <td>{{item.tackle == '' ? '无' : item.tackle}}</td>
                        <td>{{item.startaddress}}</td>
                        <td>{{item.startbed}}</td>
                        <td>
                            <div>
                                <span class="inline-block" v-for="staff in item.receive">{{staff.receive}}<a href="javascript:void(0)" class="hint tel"><span class="hint-txt">{{staff.tel}}</span></a>　</span>
                            </div>
                        </td>
                        <td>
                            <el-tooltip  placement="top" effect="light" popper-class="printTime">
                                 <div class="printTime"  slot="content">
                                        打印时间：
                                        <ul>
                                            <li v-for="printitem in item.print_flows">
                                                {{printitem.ctime}}
                                            </li>
                                        </ul>
                                    </div>
                                <div class="print-status" v-if="item.print_flows.length>0">
                                    <span></span>

                                </div>
                            </el-tooltip>
                        </td>
                        <td class="icon-comment-td" @click.stop="showCommentPop(item)"><img :src="item.evaIcon" alt=""></td>
                    </tr>
                    <!--已完成（急单，销单，预约单，普通单）-->
                    <tr v-for="(item,index) in done"
                        :class="['done',{'del':item.attribute == 4 || item.attribute == 9,'selected':item.selected}]"
                        @click.stop="lookDetail(item.id,index,1)">
                        <td @click.stop="handleSelectPrint(1,index)"><a :class="['select-btn',{'select':item.selected}]"></a></td>
                        <td>{{item.sn}}</td>
                        <td>
                            <span>{{$root.$data.sOrderAttr[item.attribute].name}}</span>
                        </td>
                        <td>
                            <span >{{$root.$data.sStatus[item.statu]}}</span>
                        </td>
                        <td>
                            <span v-if="item.istoday" class="istoday"></span>
                            <span>{{item.completetime}} 完成</span>
                            <div v-if="item.attribute ==2 || item.attribute == 8">
                                预约时间 {{item.appointment.substring(5)}}
                            </div>
                        </td>
                        <td>{{item.classifyname}}/{{item.catalogname}}</td>
                        <td>{{item.tackle == '' ? '无' : item.tackle}}</td>
                        <td>{{item.startaddress}}</td>
                        <td>{{item.startbed}}</td>
                        <td>
                            <div>
                                <span class="inline-block" v-for="staff in item.receive">{{staff.receive}}<a href="javascript:void(0)" class="hint tel"><span class="hint-txt">{{staff.tel}}</span></a>　</span>
                            </div>
                        </td>
                        <td>
                            <el-tooltip  placement="top" effect="light" popper-class="printTime">
                                <div class="printTime" slot="content">
                                        打印时间：
                                    <ul>
                                        <li v-for="printitem in item.print_flows">
                                            {{printitem.ctime}}
                                        </li>
                                    </ul>
                                </div>
                                <div class="print-status" v-if="item.print_flows.length>0">
                                    <span></span>

                                </div>
                            </el-tooltip>
                        </td>
                        <td class="icon-comment-td" @click.stop="showCommentPop(item)"><img :src="item.evaIcon" alt=""></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 输送评价功能 -->
        <div class="comment-pop" v-if="isShowPop">
            <div class="pop-bg" @click.stop="closeCommentPop(0)"></div>
            <div :class="[`${currIcon}-active`, 'comment']">
                <div class="comment-icon comment-layout icon-laugh" @click.stop="selectCommentIcon('laugh')">
                    <img src="../assets/img/face-laugh.png" alt="">
                </div>
                <div class="comment-icon comment-layout icon-cry" @click.stop="selectCommentIcon('cry')">
                    <img src="../assets/img/face-cry.png" alt="">
                </div>
                <div class="comment-area comment-layout" v-if="currIcon == 'cry'">
                    <textarea cols="30" rows="10" v-model="commentText" placeholder="请填写投诉、意见及建议，我们将第一时间为您处理。"></textarea>
                </div>
                <button type="button" class="send-btn comment-layout" v-if="currIcon != 'default'" @click.stop="sendComment()">确认</button>
            </div>
        </div>
        <!--维修-->
        <div class="comment-pop mt-comment-pop" v-if="isShowMtPop">
            <div class="pop-bg" @click.stop="closeCommentPop(1)"></div>
            <div class="comment mt-comment">
                <h2>服务星级评定</h2>
                <div class="star-line">
                    <div class="star-part">
                        <span
                            v-for="(item, index) in 5"
                            :key="index"
                            :class="[item > currStar ? 'no-select' : 'curr-select']"
                            @click="switchStar(item)"
                            @mouseover="switchStar(item)">
                        </span>
                    </div>
                    <div class="face-part">
                        <img :src="currStar <= 3 ? commentImage[1].src : commentImage[2].src" alt="">
                    </div>
                </div>
                <textarea class="mt-area" v-model="commentMtText" placeholder="请填写投诉、意见及建议，我们将第一时间为您处理"></textarea>
                <div class="mt-btn-box">
                    <button type="button" @click.stop="closeCommentPop(1)">取消</button>
                    <button type="button" :disabled="currStar <= 3 && commentMtText.trim() == '' ? true : false" @click.stop="sendMtComment">提交评价</button>
                </div>
            </div>
        </div>

        <!-- 被服申领 -->
        <div class="cloth not-print" v-if="!isLoad && currNavTab == 'cloth'" style="height:100%">
            <cloth-application></cloth-application>
        </div>
        <!--详情，操作-->
        <div class="pop-bg not-print" v-if="isLook" @click="closeLook"></div>
        <order-detail
            v-if="isLook"
            :detail="showLis"
            :handles="handle"
            :showdate="isToday"
            :set-bad-status="needSetBad"
            :types="currNavTab"
            @reminder="reminderFn"
            @cancel="cancelFn"
            @repeat="repeatFn"
            @getData="getDetailData"
        ></order-detail>

    </div>
</template>
<script>
    import today from '../common/today'
    import dateComponents from '../tips/calendar2.vue'
    import orderDetail from '../tips/order-detail.vue'
    import load from '../tips/load.vue'
    import {
        infoUrl, dayLisUrl, monthLisUrl,
        commentUrl, editUrl, cancelUrl,
        mtCommentUrl, mtDetailsUrl, mtOrderUrl,
        mtCancelUrl
    } from '../common/ajax'
    import DatePicker from 'vue2-datepicker'
    import clothApplication from '../components/clothing/clothingApplication'
    export default {
        props:{
            start:'',
            roomLis:{
                type:Array,
                default:[]
            },
            needSetBad:'',
            siteAlias:{
                type:Array,
                default:[]
            },
            lisNavTabKey:''
        },
        data(){
            function getPrintSortStatus(){
                let s = localStorage.getItem('ekt_print_sort');
                if(s == 'true'){
                    return true
                }
                return false
            }
            function getFiltrateKey(){
                let s = localStorage.getItem('ekt_ss_show_key');
                if(s && ['1','2','3','4'].indexOf(s) != -1){
                    return s
                }
                return '1'
            }
            return{
                chickIdDoing:-1,
                chickIdDone:-1,
                createdTime:'',
                todaytime:today.init('YY-MM-DD'),
                peo:[],
                statuTxt:'',
                showLis:{
                    appointment: '',
                    attribute: 0,
                    cancelname:'',
                    catalogname: "",
                    classifyname: "",
                    completetime: "",
                    createdtime: "",
                    finishaddress: "",
                    finishbed: "",
                    founder: "",
                    id:'',
                    isback: "",
                    level: "",
                    message: "",
                    quantity: "",
                    receive:'',
                    sn: "",
                    startaddress: "",
                    startbed: "",
                    statu: "",
                    tackle: ""
                },
                statShowLis:{
                    appointment: '',
                    attribute: 0,
                    cancelname:'',
                    catalogname: "",
                    classifyname: "",
                    completetime: "",
                    createdtime: "",
                    finishaddress: "",
                    finishbed: "",
                    founder: "",
                    id:'',
                    isback: "",
                    level: "",
                    message: "",
                    quantity: "",
                    receive:'',
                    sn: "",
                    startaddress: "",
                    startbed: "",
                    statu: "",
                    tackle: ""
                },    //开始的
                filtrateKey: getFiltrateKey(), //
                filtrateLis:[
                    {title:'',key:'1',name:'与我相关'},
                    {title:'默认起点和订单起点科室相同的',key:'2',name:'起点科室'},
                    {title:'默认起点和订单终点科室相同的',key:'3',name:'终点科室'},
                    {title:'',key:'4',name:'由我创建'}
                ],
                ssAllOrder:{
                    doing:[],
                    done:[]
                },
                doing:[],
                done:[],
                isLoad: false,
                isLook: false,
                //时间
                orderTime:{time:today.tmr(0)},
                orderOption:{
                    type: 'day',
                    week: ['一', '二', '三', '四', '五', '六', '日'],
                    month: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                    format: 'YYYY-MM-DD',
                    placeholder: '预约时间',
                    inputStyle: {
                        'width': '120px',
                        'text-align': 'center',
                        'padding': '5px',
                        'border-radius': '6px',
                        'border': '2px solid #66bea7',
                        'color':'#79787b'
                    },
                    color: {
                        header: '#46bd9e',
                        headerText: '#fff'
                    },
                    buttons: {
                        ok: '确定',
                        cancel: '取消'
                    },
                    overlayOpacity: 0.5, // 0.5 as default
                    dismissible: true // as true as default
                },
                limit: [
                    {
                        type: 'fromto',
                        to: ''
                    }
                ],
                isToday:true,
                //状态
                handle:{
                    appraise:false,
                    cancel:false,
                    repeat:false,
                    reminder:false
                },
                //
                detailId: '',
                detailIndex: '',
                detailShow: '',
                hasAlter:false,
                //
                selectPrint: 0,
                allPrint: 0,
                noPrintList: [],
                badSortChecked:getPrintSortStatus(),
                // 月份
                monthVal: `${new Date().getFullYear()}-${`00${new Date().getMonth()+1}`.substr(-2)}`,
                isShowList: 'day',  // day:单日查询 month:月份流水
                currTab: 'day',     // tab
                monthLis: [],
                typeVal: '',    // 月份流水input
                //评价
                isShowPop: false,
                currIcon:'default',
                currInfoId: '',
                commentText: '',
                commentImage: [
                    {src:require('../assets/img/face-l.png')},
                    {src:require('../assets/img/face-cry-l.png')},
                    {src:require('../assets/img/face-laugh-l.png')},
                ],
                tabList: [],
                currNavTab: '',
                mtDoing: [],
                mtDone: [],
                mtView: [
                    { title: '总数', num: 0 },
                    { title: '待分配', num: 0 },
                    { title: '待接单', num: 0 },
                    { title: '已接单', num: 0 },
                ],
                currStar: 5,
                isShowMtPop: false,
                currMtId: '',
                commentMtText: ''
            }
        },
        watch:{
            'lisNavTabKey':function(oldVal,Val){
                this.switchNavTab(this.lisNavTabKey)
            }
        },
        methods:{
            //维修
            doAjaxMtFn(id,des){
                //销单
                let dataj = {id: id}
                if(des){
                    dataj['msg'] = des
                }
                jQuery.ajax({
                    url: mtCancelUrl,
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    data: dataj,
                    success: function(data) {
                        this.$Message({type:'error',message:'销单成功！'});
                        this.isLook = false;
                    }.bind(this)
                })
            },
            getMtOrder(){
                //获取列表
                this.isLoad = true
                jQuery.ajax({
                    url: mtOrderUrl,
                    type: 'get',
                    cache: false,
                    success: function(data){
                        this.isLoad = false
                        if(data.success){
                            this.mtDoing = data.data.ing.reverse();
                            this.mtDone = data.data.done.reverse();
                            this.setEvaIcon();
                        }else {
                            throwErrorTips('获取维修单失败', data.msg)
                        }
                    }.bind(this),
                    error:res=>{
                        this.isLoad = false
                    }
                })
            },
            sendMtComment(){
                //评价
                if(this.currStar <= 3 && this.commentMtText.trim() == ''){
                    this.$Message({type:'error',message:'意见及建议不能为空！'});
                    return;
                }

                let form = {
                    id: this.currMtId,
                    level: this.currStar,
                    des: this.commentMtText.trim()
                }
                jQuery.ajax({
                    url: mtCommentUrl,
                    type: 'post',
                    data: form,
                    success: function(data){
                        if(data.success){
                            this.isShowMtPop = false;
                            this.commentMtText = '';
                            this.currStar = 5;
                            this.$Message({type:'success',message:'提交成功！'});
                            this.getMtOrder();
                        }else {
                            throwErrorTips('评价失败', data.msg)
                        }
                    }.bind(this)
                })
            },
            switchStar(num){
                this.currStar = num;
            },
            showMtDetails(id, num){ // num:0 未完成 1 已完成
                jQuery.ajax({
                    url: mtDetailsUrl,
                    type: 'get',
                    data: {id: id},
                    success: function(data){
                        if(data.success){
                            this.showLis = data.data;
                            this.isLook = true;
                        }
                    }.bind(this)
                })
            },
            setEvaIcon(){
                for(let value of this.mtDoing){
                    if(value.evaluate.length == 0){
                        value['evaIcon'] = this.commentImage[0].src;
                    }else if(value.evaluate[0].level <= 3){
                        value['evaIcon'] = this.commentImage[1].src;
                    }else if(value.evaluate[0].level > 3){
                        value['evaIcon'] = this.commentImage[2].src;
                    }
                    switch(value.statu){
                        case '待主管分配': this.mtView[1].num++; break;
                        case '待接单': this.mtView[2].num++; break;
                        case '已接单': this.mtView[3].num++; break;
                    }
                }
                for(let value of this.mtDone){
                    if(value.evaluate.length == 0){
                        value['evaIcon'] = this.commentImage[0].src;
                    }else if(value.evaluate[0].level <= 3){
                        value['evaIcon'] = this.commentImage[1].src;
                    }else if(value.evaluate[0].level > 3){
                        value['evaIcon'] = this.commentImage[2].src;
                    }
                }
                this.mtView[0].num = this.mtDoing.length + this.mtDone.length
            },
            showMtCommentPop(item){
                if(item.statu != '已完成'){
                    this.$Message({type:'error',message:'完成订单才可评价'});
                    return;
                }
                this.isShowMtPop = true;
                this.currMtId = item.id;
            },
            //切换显示维修，输送
            switchNavTab(key){

                this.currNavTab = key;
                if(key == 'mtain'){
                    this.mtView = this.mtView.map(v => {
                        return{
                            ...v,
                            num: 0
                        }
                    })
                    this.getMtOrder();
                }

            },
            //
            showList(text){
                this.isShowList = text;
                this.currTab = text;
                this.typeVal = '';
                this.loadLis()
            },
            sendComment(){
                //评价
                if(this.currIcon == 'default') return;
                if(this.currIcon == 'cry' && this.commentText.trim() == ''){
                    this.$Message({type:'error',message:'意见及建议不能为空！'});
                    return;
                }
                let form = {
                    id: this.currInfoId,
                    evaluation: this.currIcon == 'laugh' ? '2' : '1',
                    evaluation_txt: this.commentText
                }
                jQuery.ajax({
                    url: commentUrl,
                    type: 'post',
                    data: form,
                    dataType: 'json',
                    success: function(data){
                        if(data.success){
                            this.isShowPop = false;
                            this.commentText = '';
                            this.loadLis();
                        }else {
                            throwErrorTips('评价失败',data.msg)
                        }
                    }.bind(this)
                })
            },
            selectCommentIcon(text){
                this.currIcon = text;
            },
            closeCommentPop(num){
                num == 0 ? this.isShowPop = false : this.isShowMtPop = false
                this.currIcon = 'default';
            },
            showCommentPop(item){
                if(item.evaluation != '0') {
                    this.$Message({type:'error',message:'订单不能重复评价哦！'});
                    return;
                }
                this.currInfoId = item.id;
                this.currIcon = 'default';
                this.isShowPop = true;
            },
            //输送单日列表的显示
            handleSetKeyShowLis(key){
                this.filtrateKey = key;
                window.localStorage.setItem('ekt_ss_show_key',key)
                this.handleFiltrateShow()
            },
            //加载列表
            loadLis(){
                if(!this.isLoad){
                    let url, form;
                    this.isLoad = true;
                    if(this.currTab == 'month'){
                        url = monthLisUrl,
                            form = {
                                month: typeof(this.monthVal) == 'object' ? `${new Date(this.monthVal).getFullYear()}-${`00${new Date(this.monthVal).getMonth()+1}`.substr(-2)}` : this.monthVal,
                                key: this.typeVal
                            }
                    }else{
                        this.ssAllOrder = {doing:[],done:[]}
                        this.noPrintList = [];
                        this.selectPrint = 0;
                        this.orderTime.time == today.tmr2(0,this.todaytime) ? this.isToday = true: this.isToday = false;
                        url = dayLisUrl,
                            form = {"day":this.orderTime.time}
                    }
                    jQuery.ajax({
                        url: url,
                        type:'post',
                        dataType: 'json',
                        data:form,
                        cache: false,
                        success: function(data) {
                            this.isLoad = false;
                            if(data.success){
                                if(data.data.length == 0) {
                                    this.monthLis = [];
                                    this.isLoad = false;
                                    return;
                                }
                                if(this.currTab == 'day') this.setDayList(data)
                                if(this.currTab == 'month') this.setMonthList(data)
                            }else {
                                throwErrorTips('获取订单列表失败',data.msg)
                            }
                        }.bind(this),
                        error:function(){
                            this.isLoad = false;
                        }.bind(this)
                    });
                }
            },
            setMonthList(data){
                this.monthLis = []
                let d = data.data;
                let w = [] , dai = [] , ing = [];
                let td = this.orderTime.time;
                let pt = ['1','2','3','4'];
                let hist = ['7','8','9','10'];
                for(var i = 0; i < d.length; i++){
                    if(d[i].len > 0){
                        this.monthLis.push({
                            currYear: d[i].key.substring(0,4),
                            currMonth: d[i].key.substring(5,7),
                            currDate: d[i].key.substring(8,10),
                            len: d[i].len
                        })
                        for(var item of d[i].vals){
                            item['selected'] = false;
                            item['istoday'] = false;
                            item.sn = item.sn.substring(item.sn.length - 5);
                            let cd = item.createdtime.substring(0,10);
                            let hd = item.hiscreatedtime.substring(0,10);
                            let ispt = pt.indexOf(item.attribute);
                            item['isHis'] = false

                            if(hist.indexOf(item.attribute) != -1){
                                item['isHis'] = true
                            }
                            if( (ispt != -1 && cd == td) || (ispt == -1 && hd == td)){
                                item.istoday = true;
                            }
                            if(item.statu == 4){
                                w.push(item)
                            }
                            if(item.statu == 1){
                                dai.push(item)
                            }
                            if(item.statu == 3){
                                ing.push(item)
                            }
                            if(item.print_flows.length == 0){
                                this.noPrintList.push(item)
                            }
                            switch(item.evaluation){
                                case '1': item['evaIcon'] = this.commentImage[1].src;break;
                                case '2': item['evaIcon'] = this.commentImage[2].src;break;
                                default: item['evaIcon'] = this.commentImage[0].src;break;
                            }
                            this.monthLis.push(item)
                        }
                    }
                }
            },
            setDayList(data){
                let d = data.data;
                let dingl = d.ing.sort(function(a,b){
                    return b.id - a.id
                });
                let w = [] , dai = [] , ing = [];
                let td = this.orderTime.time;
                let pt = ['1','2','3','4'];
                let hist = ['7','8','9','10'];
                for(var val of dingl){
                    val['selected'] = false;
                    val['istoday'] = false;
                    val.sn = val.sn.substring(val.sn.length-5);
                    let cd = val.createdtime.substring(0,10);
                    let hd = val.hiscreatedtime.substring(0,10);
                    let ispt = pt.indexOf(val.attribute);
                    val['isHis'] = false
                    if(hist.indexOf(val.attribute) != -1){
                        val['isHis'] = true
                    }
                    if( (ispt != -1 && cd == td) || (ispt == -1 && hd == td)){
                        val.istoday = true;
                    }
                    if(val.statu == 4){
                        w.push(val)
                    }
                    if(val.statu == 1){
                        dai.push(val)
                    }
                    if(val.statu == 3){
                        ing.push(val)
                    }
                    switch(val.evaluation){
                        case '1': val['evaIcon'] = this.commentImage[1].src;break;
                        case '2': val['evaIcon'] = this.commentImage[2].src;break;
                        default: val['evaIcon'] = this.commentImage[0].src;break;
                    }
                }
                this.ssAllOrder.doing = w.concat(dai,ing);
                let del = [];
                for(var value of d.done){
                    value['selected'] = false;
                    value['istoday'] = false;
                    value.sn = value.sn.substring(value.sn.length-5);
                    let cds = value.createdtime.substring(0,10);
                    let hds = value.hiscreatedtime.substring(0,10);
                    let ispts = pt.indexOf(value.attribute);
                    value['isHis'] = false
                    if(hist.indexOf(value.attribute) != -1){
                        value['isHis'] = true
                    }
                    if( (ispts != -1 && cds == td) || (ispts == -1 && hds == td)){
                        value.istoday = true;
                    }
                    (value.attribute == 4 || value.attribute == 9) ?
                        del.push(value) : this.ssAllOrder.done.push(value)

                    switch(value.evaluation){
                        case '1': value['evaIcon'] = this.commentImage[1].src;break;
                        case '2': value['evaIcon'] = this.commentImage[2].src;break;
                        default: value['evaIcon'] = this.commentImage[0].src;break;
                    }
                }
                this.ssAllOrder.done = this.ssAllOrder.done.concat(del);

                this.handleFiltrateShow()
            },
            handleFiltrateShow(){
                this.doing = [];
                this.done = [];
                this.noPrintList = []
                if(this.filtrateKey == 1){
                    //全部的
                    this.doing = this.ssAllOrder.doing.map(v=>{
                        return v
                    })
                    this.done = this.ssAllOrder.done.map(v=>{
                        return v
                    })
                }else if(this.filtrateKey == 2){
                    //起点
                    this.ssAllOrder.doing.forEach(v=>{
                        let ind = -1;
                        this.roomLis.forEach((rval,i)=>{
                            if(v.startaddress.indexOf(rval.name) != -1){
                                ind = i
                            }
                        })
                        if(ind != -1){
                            this.doing.push(v)
                        }
                    })
                    this.ssAllOrder.done.forEach(v=>{
                        let ind = -1;
                        this.roomLis.forEach((rval,i)=>{
                            if(v.startaddress.indexOf(rval.name) != -1){
                                ind = i
                            }
                        })
                        if(ind != -1){
                            this.done.push(v)
                        }
                    })
                }else if(this.filtrateKey == 3){
                    //终点
                    this.ssAllOrder.doing.forEach(v=>{
                        let ind = -1;
                        this.roomLis.forEach((rval,i)=>{
                            if(v.finishaddress.indexOf(rval.name) != -1){
                                ind = i
                            }
                        })
                        if(ind != -1){
                            this.doing.push(v)
                        }
                    })
                    this.ssAllOrder.done.forEach(v=>{
                        let ind = -1;
                        this.roomLis.forEach((rval,i)=>{
                                if(v.finishaddress.indexOf(rval.name) != -1){
                                ind = i
                            }
                        })
                        if(ind != -1){
                            this.done.push(v)
                        }
                    })
                }else {
                    //由我创建的
                    let uname = Cookies.get('nickname')
                    this.ssAllOrder.doing.forEach(v=>{
                        if(v.founder == uname){
                            this.doing.push(v)
                        }
                    })
                    this.ssAllOrder.done.forEach(v=>{
                        if(v.founder == uname){
                            this.done.push(v)
                        }
                    })
                }
                this.doing.forEach(v=>{
                    if(v.print_flows && v.print_flows.length == 0){
                        this.noPrintList.push(v)
                    }
                })
                this.done.forEach(v=>{
                    if(v.print_flows && v.print_flows.length == 0){
                        this.noPrintList.push(v)
                    }
                })
                this.allPrint = this.doing.length + this.done.length
            },
            //查看详情
            lookDetail(id,index,show){
                if(id == undefined) return;
                this.detailId = id
                this.detailIndex = index
                this.detailShow = show
                if(show==0){
                    this.chickIdDoing=index;
                    this.chickIdDone=-1;
                }else {
                    this.chickIdDoing=-1;
                    this.chickIdDone=index;
                }
                let hist = ['7','8','9','10'];
                jQuery.ajax({
                    url: infoUrl,
                    type:'post',
                    dataType: 'json',
                    cache: false,
                    data:{'oid':id},
                    success: function(data) {
                        if(data.success){
                            this.showLis = data.data;
                            let d =  data.data;
                            this.handle.appraise = true;
                            this.showLis['isHis'] = false
                            if(hist.indexOf(this.showLis.attribute) != -1){
                                this.showLis['isHis'] = true
                            }
                            this.showLis['isAppoint'] = false
                            if(this.showLis.attribute == 2 || this.showLis.attribute == 8){
                                this.showLis['isAppoint'] = true
                            }else if((this.showLis.attribute == 4 || this.showLis.attribute == 9) && this.showLis.appointment !='' && this.showLis.appointment != this.showLis.createdtime &&  this.showLis.appointment != this.showLis.hiscreatedtime){
                                this.showLis['isAppoint'] = true
                            }else {
                                this.showLis['isAppoint'] = false
                            }

                            if(d.statu==1 || d.statu==3){
                                d.statu==1 ?  this.handle.cancel = true: this.handle.cancel = false;
                                this.handle.reminder = true;
                                this.handle.repeat = false;
                            }
                            if(d.statu==4){
                                this.handle.cancel = true;
                                this.handle.reminder = true;
                                this.handle.repeat = false;
                            }
                            if(d.statu==2){
                                this.handle.reminder = false;
                                this.handle.repeat = true;
                                this.handle.cancel = true;
                            }
                            if(d.attribute==4 || d.attribute==9 ) {
                                this.handle.cancel = false
                            }
                            if(d.evaluation != '0'){
                                this.showLis['evaIcon'] = this.commentImage[d.evaluation].src;  // 用于在详情中显示好评/差评icon
                            }
                        }else {
                            throwErrorTips('查看详情失败',data.msg)
                        }
                        this.isLook = true;
                    }.bind(this),
                    error:function(){
                        this.isLook = true;
                    }
                });
            },
            getDetailData(){
                this.lookDetail(this.detailId, this.detailIndex, this.detailShow);
            },
            closeLook(){
                this.isLook = false;
                if(this.hasAlter){
                    this.loadLis();
                }
            },
            //相关操作
            doAjaxFn(opt,oid,des){//销单,催单Ajax
                let url = editUrl;
                let posta = {'opt':opt,'oid':oid};
                if(opt==2 && (this.showLis.attribute == 7 || this.showLis.attribute == 8 || this.showLis.attribute == 10)){
                    url = cancelUrl;
                    posta = {'oid':oid};
                }
                if(des){
                    posta['msg'] = des
                }
                jQuery.ajax({
                    url: url,
                    type:'post',
                    dataType: 'json',
                    cache: false,
                    data:posta,
                    success: function(data) {
                        this.closeLook();
                        if(data.success){
                            this.loadLis();
                            //   _this.showLis = _this.statShowLis;
                            this.handle.appraise = false;
                            this.handle.cancel = false;
                            this.handle.repeat = false;
                            this.handle.reminder = false;
                            this.createdTime = '';
                            this.statuTxt = '';
                            if(opt==2){
                                this.$Message({type:'success',message:'销单成功！'});
                            }
                            if(opt==1){
                                this.handle.reminder=true;
                                this.$Message({type:'success',message:'催单成功！'});
                            }
                        }else {
                            throwErrorTips('操作失败',data.msg)
                        }
                    }.bind(this),
                    error:function(xhr,status){
                        throwErrorTips('操作失败',status)
                    }.bind(this)
                });
            },
            cancelFn(id,des){
                if(this.currNavTab == 'mtain'){
                    this.doAjaxMtFn(id,des)
                    return;
                }
                if(this.handle.cancel==true){
                    this.handle.cancel=false;
                    //评价操作
                    this.doAjaxFn(2,id,des);
                }
            },
            reminderFn(id,statu,sn){//催单
                if(this.handle.reminder==true){
                    this.handle.reminder=false;
                    if(statu==4){
                        let socketJson = {};
                        socketJson['istobg'] = true;
                        socketJson['uid'] = '';
                        socketJson['type']='1';
                        socketJson['otype']='待分配';
                        socketJson['id'] = id;
                        socketJson['sn'] = sn;
                        socketJson['classify'] = this.showLis.classifyname;
                        socketJson['catalog'] = this.showLis.catalogname;
                        socketJson['site']= this.showLis.startaddress;
                        this.$emit('sendsocket',JSON.stringify(socketJson));
                        setTimeout(function(){
                            this.handle.reminder=true;
                            this.closeLook();
                            this.$Message({type:'success',message:'催单成功，等待指派人员！'});
                        }.bind(this),1000)
                    }else {
                        this.doAjaxFn(1,id);
                    }
                }
            },
            repeatFn(id){
                if(this.handle.repeat==true){
                    //跳转到发单那里，信息也赋值过去
                    this.$parent.repeatId=id;
                    this.$emit('goToSetRepeat');
                }
            },
            //打印
            printAll(){
                let list = this.doing.concat(this.done);
                this.handleSetPrintLis(list)
            },
            printRest(){
                let list = this.noPrintList;
                this.handleSetPrintLis(list)
            },
            handleSelectPrint(type,index){
                if(type == 0){
                    this.doing[index].selected = !this.doing[index].selected;
                    this.doing[index].selected ? this.selectPrint += 1 : this.selectPrint -= 1;
                }else {
                    this.done[index].selected = !this.done[index].selected;
                    this.done[index].selected ? this.selectPrint += 1 : this.selectPrint -= 1;
                }
            },
            printSelect(){
                if(this.selectPrint > 0){
                    let list = [];
                    for(var val of this.doing){
                        if(val.selected){
                            list.push(val)
                        }
                    }
                    for(var vals of this.done){
                        if(vals.selected){
                            list.push(vals)
                        }
                    }
                    this.handleSetPrintLis(list)
                }else {
                    this.$Message({type:'error',message:'请选择需要打印的订单'});
                }
            },
            printNoSelect(){
                if(this.selectPrint > 0){
                    let list = [];
                    for(var val of this.doing){
                        if(!val.selected){
                            list.push(val)
                        }
                    }
                    for(var vals of this.done){
                        if(!vals.selected){
                            list.push(vals)
                        }
                    }
                    this.handleSetPrintLis(list)
                }
            },
            handleChangeCheck(s){
                localStorage.setItem('ekt_print_sort',s)
            },
            handleSetPrintLis(lis){
                let list = []
                if(this.badSortChecked){
                    let numberl = [],textl = [];
                    for(var value of lis){
                        value['badCode'] = '';
                        let badArr = [];
                        value.startbed.replace(/[0-9]*(\.[0-9]*)?/g,function(e){
                            if(e){
                                badArr.push(e)
                            }
                        });
                        if(badArr.length > 0){
                            value.badCode = badArr[0]
                            numberl.push(value)
                        }else {
                            textl.push(value)
                        }
                    }
                    var newlis = numberl.sort(function(a,b){
                        return a.badCode - b.badCode
                    })
                    list = newlis.concat(textl)
                }else {
                    list = lis
                }
                this.$parent.printLis = list;
                this.$parent.isprint = true;
                this.$root.$data.printHis = false
            },
            printCancelSelect(){
                this.selectPrint = 0;
                for(var val of this.doing){
                    if(val.selected){
                        val.selected = false
                    }
                }
                for(var vals of this.done){
                    if(vals.selected){
                        vals.selected = false
                    }
                }
            }
        },
        created() {
            this.switchNavTab(this.lisNavTabKey)
            setTimeout(function(){
                if(this.todaytime != ''){
                    let t = today.init('YY-MM-DD');
                    this.orderTime.time = today.tmr2(0,t);
                    this.limit[0].to = today.tmr2(1,t);
                    this.loadLis();
                }else {
                    location.reload();
                }
            }.bind(this),160)
        },
        components:{
            'date-fill':dateComponents,
            'order-detail':orderDetail,
            DatePicker,
            load,
            'cloth-application':clothApplication
        }
    }
</script>
<style scoped lang="less">
    .conMain .modal-tips {
        -ms-transform:translateX(-50%);
        -webkit-transform:translateX(-50%);
        -moz-transform:translateX(-50%);
        -o-transform:translateX(-50%);
        transform:translateX(-50%);
    }
</style>
